#pragma once

#include <vector>

namespace jianzhi_004
{

class Solution
{
public:
    bool findNumberIn2DArray(const std::vector< std::vector<int> >& matrix, int target)
    {
        if (matrix.empty() || matrix.front().empty())
            return false;

        int r = (int)matrix.size() - 1;
        int c = 0;
        while (r >= 0 && c < (int)matrix.front().size()) {
            if (matrix.at(r).at(c) == target)
                return true;
            if (target < matrix.at(r).at(c))
                --r;
            else
                ++c;
        }
        return false;
    }
};

}  /* namespace jianzhi_004 */
